/*
包含n个接收组件通知触发mutation调用间接更新状态的方法对象
 */
import storageUtils from '../utils/storageUtils'
import {ADD_TODO,DEL_TODO,SELECT_ALL_TODOS,DEL_COMPLETE_TODOS,RECEIVE_TODOS} from "./mutationTypes";

export default {
    addTodo({commit},todo){
        commit(ADD_TODO,{todo});  // 传递给mutation的必须是一个包含数据的对象
    },
    deleteTodo({commit},index){
        commit(DEL_TODO,{index});
    },
    selectAllTodos({commit},isChecked){
        commit(SELECT_ALL_TODOS,{isChecked});
    },
    deleteCompleteTodos({commit}){
        commit(DEL_COMPLETE_TODOS)
    },
    requestTodos({commit}){
        setTimeout(()=>{
            const todos = storageUtils.readTodos();
            commit(RECEIVE_TODOS,{todos})
        },1000)
    }
}